<?xml version='1.0' encoding='iso-8859-1'?>
<!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
	<head>
		<title>
			pev_cm_slac_param.c
			</title>
		<meta http-equiv='content-type' content='text/html;iso-8859-1'/>
		<meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
		<meta name='author' content='cmaier@cmassoc.net'/>
		<meta name='robots' content='noindex,nofollow'/>
		<link href='toolkit.css' rel='stylesheet' type='text/css'/>
		</head>
	<body>
		<div class='headerlink'>
			[<a href='pev_cm_slac_match.c.html' title=' pev_cm_slac_match.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='pev_cm_start_atten_char.c.html' title=' pev_cm_start_atten_char.c '>NEXT</a>]
			</div>
<pre>
/*====================================================================*
 *
 *   Copyright (c) 2013 Qualcomm Atheros, Inc.
 *
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or 
 *   without modification, are permitted (subject to the limitations 
 *   in the disclaimer below) provided that the following conditions 
 *   are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials 
 *     provided with the distribution.
 *
 *   * Neither the name of Qualcomm Atheros nor the names of 
 *     its contributors may be used to endorse or promote products 
 *     derived from this software without specific prior written 
 *     permission.
 *
 *   NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE 
 *   GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE 
 *   COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR 
 *   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 *   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 *   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *
 *   signed pev_cm_slac_param (struct session * session, struct channel * channel, struct message * message);
 *
 *   slac.h
 *
 *   PEV-HLE broadcasts cm_slac_param requests until at least one
 *   matching cm_slac_param confirm is received; matching confirm 
 *   has the same run identifier; EVSE-HLE returns information to 
 *   the PEV-HLE;
 *
 *   return 0 on success, -1 on error and 1 on timeout;
 *
 *   this interaction effectivey synchronizes the PEV-HLE and one
 *   or more EVSE-HLEs by initiating the SLAC protocol sequence;
 *
 *   MSOUND-TARGET will be FF:FF:FF:FF:FF:FF for SLAC;
 *   NUM_SOUNDS will be 8 for SLAC;
 *   TIME_OUT will be 10 for SLAC;
 *   RESP_TYPE will be 00 for SLAC (???);
 *   FORWARDING_STA will be 00:00:00:00:00:00 for SLAC when RESP_TYPE=0;
 *   APPLICATION_TYPE will be 0 for SLAC;
 *   SECUTITY_TYPE will be 0 for this application;
 *   RunID will be that defined by PEV-HLE;
 *
 *   send cm_slac_param request then wait up to channel.timeout 
 *   milliseconds for a cm_slac_param confirm having the same 
 *   RunID as the request; the application type and security 
 *   type should be the same as in the request; 
 *
 *   save the msound target, forwarding station, number of sounds, 
 *   sounding timeout and response type for use later in the session; 
 *
 *   the forwarding stations is a vague concept; the specification 
 *   authors say it should be FF:FF:FF:FF:FF:FF but here, the EVSE-HLE
 *   will set it to the PEV MAC;
 *   
 *--------------------------------------------------------------------*/

#ifndef PEV_CM_SLAC_PARAM_SOURCE
#define PEV_CM_SLAC_PARAM_SOURCE

#include &lt;string.h&gt;
#include &lt;errno.h&gt;

#include &quot;../ether/channel.h&quot;
#include &quot;../tools/memory.h&quot;
#include &quot;../tools/error.h&quot;
#include &quot;../tools/flags.h&quot;
#include &quot;../iso15118/slac.h&quot;

signed pev_cm_slac_param (struct session * session, struct channel * channel, struct message * message) 

{ 
	extern byte const broadcast [ETHER_ADDR_LEN]; 
	struct cm_slac_param_request * request = (struct cm_slac_param_request *) (message); 
	struct cm_slac_param_confirm * confirm = (struct cm_slac_param_confirm *) (message); 
	slac_debug (session, 0, __func__, &quot;--&gt; CM_SLAC_PARAM.REQ&quot;); 
	memset (message, 0, sizeof (* message)); 
	EthernetHeader (&amp; request-&gt;ethernet, broadcast, channel-&gt;host, channel-&gt;type); 
	HomePlugHeader1 (&amp; request-&gt;homeplug, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_REQ)); 
	request-&gt;APPLICATION_TYPE = session-&gt;APPLICATION_TYPE; 
	request-&gt;SECURITY_TYPE = session-&gt;SECURITY_TYPE; 
	memcpy (request-&gt;RunID, session-&gt;RunID, sizeof (request-&gt;RunID)); 
	request-&gt;CipherSuite [0] = HTOLE16 ((uint16_t) (session-&gt;counter)); 
	if (sendmessage (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) &lt;= 0) 
	{ 
		return (slac_debug (session, 1, __func__, CHANNEL_CANTSEND)); 
	} 
	while (readmessage (channel, message, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_CNF)) &gt; 0) 
	{ 
		if (! memcmp (session-&gt;RunID, confirm-&gt;RunID, sizeof (session-&gt;RunID))) 
		{ 
			slac_debug (session, 0, __func__, &quot;&lt;-- CM_SLAC_PARAM.CNF&quot;); 
			if (confirm-&gt;APPLICATION_TYPE != session-&gt;APPLICATION_TYPE) 
			{ 
				slac_debug (session, session-&gt;exit, __func__, &quot;Unexpected APPLICATION_TYPE&quot;); 
			} 
			if (confirm-&gt;SECURITY_TYPE != session-&gt;SECURITY_TYPE) 
			{ 
				slac_debug (session, session-&gt;exit, __func__, &quot;Unexpected SECURITY_TYPE&quot;); 
			} 
			if (_anyset (session-&gt;flags, SLAC_COMPARE)) 
			{ 
				if (LE16TOH (confirm-&gt;CipherSuite) != (uint16_t) (session-&gt;counter)) 
				{ 
					slac_debug (session, session-&gt;exit, __func__, &quot;session-&gt;counter mismatch! PEV=(%d) EVSE=(%d)&quot;, LE16TOH (confirm-&gt;CipherSuite), session-&gt;counter); 
				} 
			} 

#if SLAC_DEBUG

			if (_anyset (session-&gt;flags, SLAC_VERBOSE)) 
			{ 
				char string [256]; 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.MSOUND_TARGET %s&quot;, HEXSTRING (string, confirm-&gt;MSOUND_TARGET)); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.NUM_SOUNDS %d&quot;, confirm-&gt;NUM_SOUNDS); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.TIME_OUT %d&quot;, confirm-&gt;TIME_OUT); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.RESP_TYPE %d&quot;, confirm-&gt;RESP_TYPE); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.FORWARDING_STA %s&quot;, HEXSTRING (string, confirm-&gt;FORWARDING_STA)); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.APPLICATION_TYPE %d&quot;, confirm-&gt;APPLICATION_TYPE); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.SECURITY_TYPE %d&quot;, confirm-&gt;SECURITY_TYPE); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.RunID %s&quot;, HEXSTRING (string, confirm-&gt;RunID)); 
				slac_debug (session, 0, __func__, &quot;CM_SLAC_PARAM.CNF.CipherSuite %d&quot;, confirm-&gt;CipherSuite); 
			} 

#endif

			memcpy (session-&gt;FORWARDING_STA, confirm-&gt;FORWARDING_STA, sizeof (session-&gt;FORWARDING_STA)); 
			memcpy (session-&gt;MSOUND_TARGET, confirm-&gt;MSOUND_TARGET, sizeof (session-&gt;MSOUND_TARGET)); 
			session-&gt;NUM_SOUNDS = confirm-&gt;NUM_SOUNDS; 
			session-&gt;TIME_OUT = confirm-&gt;TIME_OUT; 
			session-&gt;RESP_TYPE = confirm-&gt;RESP_TYPE; 
			return (0); 
		} 
	} 
	return (slac_debug (session, 0, __func__, &quot;&lt;-- CM_SLAC_PARAM.CNF ?&quot;)); 
} 

#endif


</pre>
		<div class='footerlink'>
			[<a href='pev_cm_slac_match.c.html' title=' pev_cm_slac_match.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='pev_cm_start_atten_char.c.html' title=' pev_cm_start_atten_char.c '>NEXT</a>]
			</div>
		</body>
	</html>
